<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>10_员工列表练习</title>
</head>
<body>
    <input type="text" placeholder="请输入员工" id="i1">
    <input type="text" placeholder="请输入工资" id="i2">
    <input type="text" placeholder="请输入岗位" id="i3">
    <button onclick="addEmp()">点击添加员工</button>
    <hr>
    <table border="1px">
      <tr>
        <th>姓名</th>
        <th>工资</th>
        <th>岗位</th>
      </tr>
    </table>
    <script>
      let arr = []
      function addEmp(){
        let uName = document.getElementById('i1').value.trim();
        let uSalary = document.getElementById('i2').value.trim();
        let uJob = document.getElementById('i3').value.trim();
        if (!uName || !uSalary || !uJob){
          alert('请完善信息！');
          return;
        }
        let trE = document.createElement('tr');
        let nameId = document.createElement('td');
        let salaryId = document.createElement('td');
        let jobId = document.createElement('td');
        nameId.innerHTML = uName;
        salaryId.innerHTML = uSalary;
        jobId.innerHTML = uJob;
        trE.append(nameId,salaryId,jobId);
        let tableE = document.querySelector('table');
        tableE.append(trE);
        document.getElementById('i1').value = '';
        document.getElementById('i2').value = '';
        document.getElementById('i3').value = '';
        arr.push({
          name : uName,
          salary : uSalary,
          job : uJob
        });
        console.log(arr);
      }
    </script>
</body>
</html>